
/**
 * AppleIIGo
 * Video Maps class
 * (C) 2008 by Marc S. Ressl (mressl@umich.edu)
 * Released under the GPL
 * Inspired by Jim Sather's "Understanding the Apple IIe"
 */

#include "Motherboard.h"

#ifndef VIDEOMAPS_H
#define VIDEOMAPS_H

typedef enum {
	RENDERMAP_TEXT,			// TEXT /80COL
	RENDERMAP_DTEXT,		// TEXT 80COL
	RENDERMAP_LORES,		// /TEXT /MIXED /HIRES /DHIRES
	RENDERMAP_7MLORES,		// /TEXT /MIXED /HIRES DHIRES /80COL
	RENDERMAP_DLORES,		// /TEXT /MIXED /HIRES DHIRES 80COL
	RENDERMAP_HIRES,		// /TEXT /MIXED HIRES /DHIRES
	RENDERMAP_7HIRES,		// /TEXT /MIXED HIRES DHIRES /80COL
	RENDERMAP_DHIRES,		// /TEXT /MIXED HIRES DHIRES 80COL
	RENDERMAP_DHIRESMONO,	// /TEXT /MIXED HIRES DHIRES 80COL
	RENDERMAP_LORESTEXT,	// /TEXT MIXED /HIRES /DHIRES /80COL
	RENDERMAP_LORESDTEXT,	// /TEXT MIXED /HIRES /DHIRES 80COL
	RENDERMAP_7MLORESTEXT,	// /TEXT MIXED /HIRES DHIRES /80COL
	RENDERMAP_DLORESDTEXT,	// /TEXT MIXED /HIRES DHIRES 80COL
	RENDERMAP_HIRESTEXT,	// /TEXT MIXED HIRES /DHIRES /80COL
	RENDERMAP_HIRESDTEXT,	// /TEXT MIXED HIRES /DHIRES 80COL
	RENDERMAP_7HIRESTEXT,	// /TEXT MIXED HIRES DHIRES /80COL
	RENDERMAP_DHIRESDTEXT,	// /TEXT MIXED HIRES DHIRES 80COL
	RENDERMAP_DHIRESMONODTEXT,	// /TEXT MIXED HIRES DHIRES 80COL
	RENDERMAP_SHIRES,		// SHIRES
	RENDERMAP_VIDEOTERM,	// VIDEOTERM
	RENDERMAP_END,
};

typedef enum {
	ADDRESSMAP_TEXTPAGE1,
	ADDRESSMAP_TEXTPAGE2,
	ADDRESSMAP_HIRESPAGE1,
	ADDRESSMAP_HIRESPAGE2,
	ADDRESSMAP_HIRESTEXTPAGE1,
	ADDRESSMAP_HIRESTEXTPAGE2,
	ADDRESSMAP_SHIRES,
	ADDRESSMAP_VIDEOTERM,
	ADDRESSMAP_END,
};

typedef enum {
	ISVIDEOMODIFIEDMAP_TEXTPAGE1,
	ISVIDEOMODIFIEDMAP_TEXTPAGE2,
	ISVIDEOMODIFIEDMAP_HIRESPAGE1,
	ISVIDEOMODIFIEDMAP_HIRESPAGE2,
	ISVIDEOMODIFIEDMAP_HIRESTEXTPAGE1,
	ISVIDEOMODIFIEDMAP_HIRESTEXTPAGE2,
	ISVIDEOMODIFIEDMAP_DTEXTPAGE1,
	ISVIDEOMODIFIEDMAP_DTEXTPAGE2,
	ISVIDEOMODIFIEDMAP_DHIRESPAGE1,
	ISVIDEOMODIFIEDMAP_DHIRESPAGE2,
	ISVIDEOMODIFIEDMAP_DHIRESDTEXTPAGE1,
	ISVIDEOMODIFIEDMAP_DHIRESDTEXTPAGE2,
	ISVIDEOMODIFIEDMAP_SHIRES,
	ISVIDEOMODIFIEDMAP_VIDEOTERM,
	ISVIDEOMODIFIEDMAP_END,
};

class VideoMaps {
public:
	VideoMaps(class VideoRenderer * videoRenderer);
	
	UINT32 ** getVideoModeToRenderMap();
	UINT32 ** getVideoModeToAddressMap();
	UINT8 ** getVideoModeToIsVideoModifiedMap();
	
private:
	class VideoRenderer * videoRenderer;
	
	UINT32 renderMaps[RENDERMAP_END][SCANLINE_END];
	UINT32 addressMaps[ADDRESSMAP_END][SCANLINE_END];
	UINT8 isVideoModifiedMaps[ISVIDEOMODIFIEDMAP_END][SHADOWMEMORY_END];
	
	UINT32 * videoModeToRenderMap[VIDEOMODE_END];
	UINT32 * videoModeToAddressMap[VIDEOMODE_END];
	UINT8 * videoModeToIsVideoModifiedMap[VIDEOMODE_END];
	
	void initAppleIIRenderMap(UINT32 * renderMap,
							  UINT32 renderModeTop,
							  UINT32 renderModeBottom);
	void initRenderMap(UINT32 * renderMap,
					   UINT32 scanlineStart,
					   UINT32 scanlineEnd,
					   UINT32 renderMode);
	void initRenderMaps();
	
	UINT32 getShadowAddress(UINT32 scanlineIndex, UINT32 videoMode);
	void initAddressMap(UINT32 * addressMap, UINT32 videoMode);
	void initAddressMaps();
	
	UINT8 getIsVideoModifiedAddress(UINT32 scanlineIndex, UINT32 videoMode);
	UINT32 getPitch(UINT32 videoMode);
	void initIsVideoModifiedMap(UINT8 * isVideoModifiedMap, UINT32 videoMode);
	void initIsVideoModifiedMaps();
	
	UINT32 * getRenderMap(UINT32 videoMode);
	UINT32 * getAddressMap(UINT32 videoMode);
	UINT8 * getIsVideoModifiedMap(UINT32 videoMode);
	void initVideoModeMaps();
};

#endif
